<template>
	<!-- 必须有根标签 -->
	<view>
		<!-- 搜索热区 -->
		<SearchLink/>
		
		<!-- 轮播图 -->
		<swiper indicator-dots indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#fff" autoplay circular>
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<image :src="item.image_src" mode=""></image>
			</swiper-item>
		</swiper>
		<!-- 导航层 -->
		<view class="nav">
			<image v-for="(item,index) in categoryList" :key="index" :src="item.image_src" mode=""></image>
		</view>
		<!-- 楼层 -->
		<view class="floor">
			<view class="floor-item" v-for="(floorItem,index) in floorList" :key="index">
				<image :src="floorItem.floor_title.image_src" mode=""></image>
				<!-- class名中划线分隔 -->
				<view class="product-list">
					<image :src="floorItem.product_list[0].image_src" mode=""></image>
					<view class="right">
						<!-- index为0,转成false;也就是不为0时，就会渲染 -->
						<block v-for="(item,index) in floorItem.product_list.slice(1)" :key="index">
							<image :src="item.image_src" mode=""></image>
						</block>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// 引入
	// import request from '@/utils/request'
	import SearchLink from '@/components/SearchLink'
	
	export default {
		components:{
			// SearchLink:SearchLink
			SearchLink
		},
		data() {
			return {
				swiperList: [],
				categoryList: [],
				floorList: []
			}
		},
		onLoad() {
			this.getSwiperdata()
			this.getCatitems()
			this.getFloordata()
		},
		methods: {
			// 获取楼层数据
			async getFloordata() {
				// uni.request({
				// 	url: 'https://www.uinav.com/api/public/v1/home/floordata',
				// 	success: (res) => {
				// 		let {
				// 			message,
				// 			meta
				// 		} = res.data
				// 		if (meta.status === 200) {
				// 			this.floorList = message
				// 		}
				// 	}
				// })
				this.floorList = await this.$request({
					url: '/api/public/v1/home/floordata'
				})
			},
			// 获取导航栏数据
			async getCatitems() {
				// uni.request({
				// 	url: 'https://www.uinav.com/api/public/v1/home/catitems',
				// 	success: (res) => {
				// 		let {
				// 			message,
				// 			meta
				// 		} = res.data
				// 		if (meta.status === 200) {
				// 			this.categoryList = message
				// 		}
				// 	}
				// })
				this.categoryList = await this.$request({
					url: '/api/public/v1/home/catitems'
				})
			},
			// // 公共请求方法
			// request(options) {
			// 	// 2. 修改为promise
			// 	return new Promise((resolve) => {
			// 		uni.request({
			// 			url: options.url,
			// 			success: (res) => {
			// 				// resolve(res)
			// 				let {
			// 					message,
			// 					meta
			// 				} = res.data
			// 				if (meta.status === 200) {
			// 					// 对外传message更好
			// 					resolve(message)
			// 				}
			// 			}
			// 		})
			// 	})
			// },
			// 获取轮播图数据
			async getSwiperdata() {
				this.swiperList = await this.$request({
					url: '/api/public/v1/home/swiperdata'
				})
			}
		}
	}
</script>

<style lang="less">
	.floor-item {

		// >表示子代
		>image {
			width: 100%;
			height: 88rpx;
		}

		.product-list {
			display: flex;
			padding: 20rpx 17rpx;

			>image {
				height: 386rpx;
				width: 232rpx;
			}

			.right {
				flex: 1;
				display: flex;
				flex-wrap: wrap;

				image {
					height: 188rpx;
					width: 232rpx;
					margin: 0 0 10rpx 10rpx;
				}
			}
		}
	}

	.nav {
		height: 194rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;

		image {
			width: 128rpx;
			height: 140rpx;
		}
	}

	swiper {
		height: 340rpx;

		image {
			width: 100%;
			height: 340rpx;
		}
	}
</style>
